package study.queue;

import study.array.Array;

/**
 * @Classname ArrayQueue
 * @Author happytaohaha
 * @Date 2020/3/27
 * @Description TODO
 */
public class ArrayQueue<E> implements Queue<E> {

    private Array<E> array;

    public ArrayQueue(int capacity){
        array =new Array<>(capacity);
    }

    public ArrayQueue(){
        array = new Array<>();
    }


    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public void enqueue(E e) {
        array.addLast(e);
    }

    @Override
    public E dequeue() {
        return array.removeFast();
    }

    @Override
    public E getFront() {
        return array.getFast();
    }

    public int getCapacity(){
        return array.getCapacity();
    }

    @Override
    public String toString(){
        StringBuffer res = new StringBuffer();
        res.append("ArrayQueue:");
        res.append("[");
        for(int i  = 0 ; i< array.getSize();i++){
            res.append(array.get(i));
            if(i != array.getSize()){
                res.append(", ");
            }
        }
        res.append("]  tail");
        return res.toString();
    }
}
